package org.csu.code.api.controller;

import org.apache.catalina.User;
import org.csu.code.api.common.CommonResponse;
import org.csu.code.api.entity.Rent;
import org.csu.code.api.entity.StatusMessage;
import org.csu.code.api.service.RentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class RentController {
    @Autowired
    private RentService rentService;

    @GetMapping("/rents/{id}")
    @ResponseBody
    private CommonResponse<Rent> getRentByRentId(@PathVariable("id") int rentId){
        return rentService.getRentByRentId(rentId);
    }

    @GetMapping("/accounts/{id}/rents")
    @ResponseBody
    private CommonResponse<List<Rent>> getRentsByUserId(@PathVariable("id") int userId){
        return rentService.getRentsByUserId(userId);
    }

    @GetMapping("/farms/{id}/rents")
    @ResponseBody
    private CommonResponse<List<Rent>> getRentsByFarmerId(@PathVariable("id") int farmerId){
        return rentService.getRentsByFarmerId(farmerId);
    }

    @PostMapping("/rents")
    @ResponseBody
    private CommonResponse<String> rent(@RequestBody Rent rent){
        return rentService.rent(rent);
    }

    @PutMapping("rents/{id}")
    @ResponseBody
    private CommonResponse<String> handle(@PathVariable("id") int rentId, @RequestBody StatusMessage statusMessage){
        return rentService.handle(rentId, statusMessage);
    }

    @DeleteMapping("/rents/{id}")
    @ResponseBody
    public CommonResponse<Rent> deleteRent(@PathVariable("id") int rentId){return rentService.deleteRent(rentId);}

}
